import {
  Controller,
  Post,
  Body,
  UseGuards,
  Request,
  Get,
} from '@nestjs/common';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
} from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { VipService } from './vip.service';
import {
  CreateVipOrderDto,
  VipOrderResponseDto,
  ApiVipOrderResponseDto,
  VipInfoResponseDto,
  ApiVipInfoResponseDto,
  ApiPointsOrderResponseDto,
  CreatePointsOrderDto,
  ApiPointsBalanceResponseDto,
  ApiSignInResponseDto,
  ApiSignInListResponseDto,
  ApiSignInStatusResponseDto,
} from './dto/vip.dto';

@ApiTags('VIP服务')
@Controller('vip')
export class VipController {
  constructor(private readonly vipService: VipService) {}

  @Post('purchase')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: '购买VIP' })
  @ApiResponse({
    status: 200,
    description: '购买成功',
    type: ApiVipOrderResponseDto,
  })
  @ApiResponse({ status: 400, description: '参数错误' })
  @ApiResponse({ status: 401, description: '未授权' })
  async purchaseVip(@Request() req, @Body() purchaseDto: CreateVipOrderDto) {
    const userId = req.user.id;
    return this.vipService.purchaseVip(userId, purchaseDto);
  }

  @Get('info')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: '获取VIP信息' })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: ApiVipInfoResponseDto,
  })
  @ApiResponse({ status: 401, description: '未授权' })
  async getVipInfo(@Request() req) {
    const userId = req.user.id;
    return this.vipService.getVipInfo(userId);
  }

  @Get('packages')
  @ApiOperation({ summary: '获取VIP套餐列表' })
  @ApiResponse({ status: 200, description: '获取成功' })
  async getVipPackages() {
    return this.vipService.getVipPackages();
  }

  @Post('points/purchase')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: '购买积分' })
  @ApiResponse({
    status: 200,
    description: '购买成功',
    type: ApiPointsOrderResponseDto,
  })
  @ApiResponse({ status: 400, description: '参数错误' })
  @ApiResponse({ status: 401, description: '未授权' })
  async purchasePoints(
    @Request() req,
    @Body() purchaseDto: CreatePointsOrderDto,
  ) {
    const userId = req.user.id;
    return this.vipService.purchasePoints(userId, purchaseDto);
  }

  @Get('points/packages')
  @ApiOperation({ summary: '获取积分套餐列表' })
  @ApiResponse({ status: 200, description: '获取成功' })
  async getPointsPackages() {
    return this.vipService.getPointsPackages();
  }

  @Get('points/packages/recommended')
  @ApiOperation({ summary: '获取推荐积分套餐' })
  @ApiResponse({ status: 200, description: '获取成功' })
  async getRecommendedPointsPackages() {
    return this.vipService.getRecommendedPointsPackages();
  }

  @Get('points/packages/stats')
  @ApiOperation({ summary: '获取积分套餐统计信息' })
  @ApiResponse({ status: 200, description: '获取成功' })
  async getPointsPackagesStats() {
    return this.vipService.getPointsPackagesStats();
  }

  @Get('points/balance')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: '获取用户积分余额' })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: ApiPointsBalanceResponseDto,
  })
  @ApiResponse({ status: 401, description: '未授权' })
  async getPointsBalance(@Request() req) {
    const userId = req.user.id;
    return this.vipService.getPointsBalance(userId);
  }

  @Post('signin')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: '用户签到' })
  @ApiResponse({
    status: 200,
    description: '签到成功',
    type: ApiSignInResponseDto,
  })
  @ApiResponse({ status: 400, description: '今日已签到' })
  @ApiResponse({ status: 401, description: '未授权' })
  async signIn(@Request() req) {
    const userId = req.user.id;
    return this.vipService.signIn(userId);
  }

  @Get('signin/list')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: '获取用户签到记录列表' })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: ApiSignInListResponseDto,
  })
  @ApiResponse({ status: 401, description: '未授权' })
  async getSignInList(@Request() req) {
    const userId = req.user.id;
    return this.vipService.getSignInList(userId);
  }

  @Get('signin/status')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: '获取用户今日签到状态' })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: ApiSignInStatusResponseDto,
  })
  @ApiResponse({ status: 401, description: '未授权' })
  async getSignInStatus(@Request() req) {
    const userId = req.user.id;
    return this.vipService.getSignInStatus(userId);
  }
}
